<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head>
  <title>工人信息</title>
  <style type="text/css">
    table {
      border-collapse: collapse;
      width: 75%;
      border: 1px solid;
    }
  </style>
</head>
<body>
<div align="center">
  <s:a href="projectAction">工程信息</s:a>
  <s:include value="add.jsp" />
  <fieldset>
    <s:form id="query.form" action="workerAction!queryById.action" method="get" style="width: 260px">
      <legend>查询条件</legend>
      <s:select label="查询条件" onchange="queryCondition(this.value)" list="#{'id':'工人id','name':'工人姓名','telephone':'电话'}" />
      <s:textfield id="condition" name="worker.workerId" label="查询字段" title="工人id" />
      <s:submit value="查询" />
    </s:form>
  </fieldset>
  <table>
    <tr>
      <th>工人id</th>
      <th>工人姓名</th>
      <th>工人性别</th>
      <th>工人电话</th>
      <th>工程id</th>
      <th>操作</th>
    </tr>
    <s:if test="workers.size>0">
      <s:iterator value="workers" var="obj">
        <tr>
          <td><s:property value="#obj.workerId" /></td>
          <td><s:property value="#obj.workerName" /></td>
          <td>
            <s:if test="#obj.sex==1">
              <s:property value="'男'" />
            </s:if>
            <s:else>
              <s:property value="'女'" />
            </s:else>
          </td>
          <td><s:property value="#obj.telephone" /></td>
          <td><s:property value="#obj.projectId" /></td>
          <td>
            <s:a href="workerAction!edit?worker.workerId=%{#obj.workerId}">修改</s:a>
            <s:a href="workerAction!remove?worker.workerId=%{#obj.workerId}">删除</s:a>
          </td>
        </tr>
      </s:iterator>
    </s:if>
  </table>
</div>
</body>
<script>
  function queryCondition(val) {
    if (val != null) {
      var element = document.getElementById("condition");
      var form = document.getElementById("query.form");
      var value = element.value;
      if (val === "id") {
        element.name = "worker.workerId";
        element.title = "工人id";
        form.action = "workerAction!queryById.action";
      } else if (val === "name") {
        element.name = "worker.workerName";
        element.title = "工人名称";
        form.action = "workerAction!queryByName.action";
      } else if (val === "telephone") {
        element.name = "worker.telephone";
        element.title = "电话";
        form.action = "workerAction!queryByTelephone.action";
      }
    }
  }
</script>
</html>
